package com.cDesarrollador.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.cDesarrollador.model.Venta;

public class VentaDAO implements IVentaDAO {
	

	 private SessionFactory sessionFactory;
	 
	    /**
	     * Get Hibernate Session Factory
	     *
	     * @return SessionFactory - Hibernate Session Factory
	     */
	    public SessionFactory getSessionFactory() {
	        return sessionFactory;
	    }
	 
	    /**
	     * Set Hibernate Session Factory
	     *
	     * @param SessionFactory - Hibernate Session Factory
	     */
	    public void setSessionFactory(SessionFactory sessionFactory) {
	        this.sessionFactory = sessionFactory;
	    }
	 
	    /**
	     * Add Venta
	     *
	     * @param  Venta Venta
	     */
	   
	    public void addVenta(Venta Venta) {
	        getSessionFactory().getCurrentSession().save(Venta);
	    }
	 
	    /**
	     * Delete Venta
	     *
	     * @param  Venta Venta
	     */
	 
	    public void deleteVenta(Venta Venta) {
	        getSessionFactory().getCurrentSession().delete(Venta);
	    }
	 
	    /**
	     * Update Venta
	     *
	     * @param  Venta Venta
	     */
	   
	    public void updateVenta(Venta Venta) {
	        getSessionFactory().getCurrentSession().update(Venta);
	    }
	 
	    /**
	     * Get Venta
	     *
	     * @param  int Venta Id
	     * @return Venta
	     */
	   
	    public Venta getVentaById(int id) {
	        List list = getSessionFactory().getCurrentSession()
	                                            .createQuery("from Venta where id=?")
	                                            .setParameter(0, id).list();
	        return (Venta)list.get(0);
	    }
	 
	    /**
	     * Get Venta List
	     *
	     * @return List - Venta list
	     */
	   
	    public List<Venta> getVentas() {
	        List list = getSessionFactory().getCurrentSession().createQuery("from Venta").list();
	        return list;
	    }

}
